package cn.tedu.eb_film.controller;


import cn.tedu.eb_film.pojo.dto.CsChangeRegulationDto;
import cn.tedu.eb_film.pojo.dto.CsChangeRegulationUpdateDto;
import cn.tedu.eb_film.pojo.entity.CsChangeRegulation;
import cn.tedu.eb_film.pojo.vo.CsChangeRegulationVo;
import cn.tedu.eb_film.service.CsChangeRegulationService;
import cn.tedu.eb_film.utils.JsonResult;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/CsChangeRegulation")
@Api(tags = "改签标准")
@Slf4j
public class CsChangeRegulationController {
    @Autowired
    CsChangeRegulationService csChangeRegulationService;

    /**
     * 插入单个改签标准
     * @param csChangeRegulationDto
     * @return
     */
    @PostMapping("/AddNewChangeRegulation")
    public JsonResult<Void> AddNewChangeRegulation(@RequestBody CsChangeRegulationDto csChangeRegulationDto){
        csChangeRegulationService.AddNewChangeRegulation(csChangeRegulationDto);
        return JsonResult.ok();
    }

    /**
     * 批量插入改签标准
     * @param list
     * @return
     */
    @PostMapping("/AddNewChangeRegulationList")
    public JsonResult<Void> AddNewChangeRegulationList(List<CsChangeRegulation> list){
        csChangeRegulationService.AddNewChangeRegulationList(list);
        return JsonResult.ok();
    }

    /**
     * 根据id删除改签标准
     * @param id
     * @return
     */
    @PostMapping("/deleteChangeRegulationById")
    public JsonResult<Void> deleteChangeRegulationById(Long id){
        csChangeRegulationService.deleteChangeRegulationById(id);
        return JsonResult.ok();
    }

    /**
     * 根据ids集合删除改签标准
     * @param list
     * @return
     */
    @PostMapping("/deleteChangeRegulationByIds")
    public JsonResult<Void> deleteChangeRegulationByIds(List<Long> list){
        csChangeRegulationService.deleteChangeRegulationByIds(list);
        return JsonResult.ok();
    }

    /**
     * 统计改签标准集合
     * @return
     */
    @GetMapping("/countChangeRegulation")
    public JsonResult<Void> countChangeRegulation(){
        csChangeRegulationService.countChangeRegulation();
        return JsonResult.ok();
    }

    /**
     * 根据id获取改签标准
     * @param id
     * @return
     */
    @PostMapping("/getChangeRegulationById")
    public JsonResult<CsChangeRegulationVo> getChangeRegulationById(Integer  id){
        CsChangeRegulationVo changeRegulationById = csChangeRegulationService.getChangeRegulationById(id);
        return JsonResult.ok(changeRegulationById);
    }

    /**
     * 获取改签标准集合
     * @return
     */
    @GetMapping("/getChangeRegulationList")
    public JsonResult<List<CsChangeRegulationVo>> getChangeRegulationList(){
        List<CsChangeRegulationVo> list = csChangeRegulationService.getChangeRegulationList();
        return JsonResult.ok(list);
    }

    /**
     * 修改改签标准
     * @param csChangeRegulationUpdateDto
     * @return
     */
    @PostMapping("/updateChangeRegulation")
    public JsonResult<Void> updateChangeRegulation(@RequestBody CsChangeRegulationUpdateDto csChangeRegulationUpdateDto){
        csChangeRegulationService.updateChangeRegulation(csChangeRegulationUpdateDto);
        return JsonResult.ok();
    }


    @PostMapping("/search")
    public JsonResult<List<CsChangeRegulationVo>> search(@RequestBody CsChangeRegulationUpdateDto csChangeRegulationUpdateDto){
        log.info("传入参数{}",csChangeRegulationUpdateDto);
        List<CsChangeRegulationVo> list = csChangeRegulationService.search(csChangeRegulationUpdateDto.getConnect());
        return JsonResult.ok(list);
    }

    @PostMapping("/enable")
    public JsonResult<Void> setEnable(Integer id) {
        log.debug("开始处理【启用品牌】的请求，参数：{}", id);
        csChangeRegulationService.setEnable(id);
        return JsonResult.ok();
    }

    @PostMapping("/disable")
    public JsonResult<Void> setDisable( Integer id) {
        log.debug("开始处理【禁用品牌】的请求，参数：{}", id);
        csChangeRegulationService.setDisable(id);
        return JsonResult.ok();
    }
}
